﻿
@{
    ViewBag.Title = "淘宝订单-物流比价";
    Layout = "~/Views/Shared/_LayoutEasyUI.cshtml";
}

<table id="grid-list"> </table>

<div id="toolbar" style="display:none;">
    <div style="margin:10px 0 5px 20px;height:35px;">
        <a id="btn" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-man'">物流初选</a>

    </div>
</div>

@section scripts{

    <script>
        $(function () {
            Grid.LoadData();
        });

        var Grid = {
            LoadData: function () {
                var url = "/Order/CompareData";
                Grid.list = $("#grid-list").datagrid({
                    url: url,
                    title: '物流比价',
                    fit: true,
                    fitColumns: true,
                    singleSelect: false,
                    rownumbers: true,
                    nowrap: false,
                    toolbar: [
                    {
                        id: 'btnConfirm',
                        iconCls: 'icon-ok',
                        text: '批量确认',
                        handler: function () {
                            var rows = $("#grid-list").datagrid('getChecked');
                            if (rows.length === 0) {
                                layer.open({
                                    type: 4,
                                    shade: 0,
                                    time: 2000,
                                    content: ['请选择需要确认比价结果的订单', '#btnConfirm']//这里content是一个普通的String
                                });
                                return;
                            };
                            var index = layer.confirm('确认批量确认物流比价结果？', function (index) {
                                layer.close(index);

                                var orderid = [];
                                $.each(rows, function (i, v) {
                                    orderid.push(v.FOrderId);
                                });
                                $.ajax({
                                    url: '/Order/ConfirmSupplier',
                                    data: {
                                        orders: JSON.stringify(orderid)
                                    },
                                    dataType: 'json',
                                    type: 'post',
                                    success: function (data) {
                                        if (data.success) {
                                            Grid.Refresh();
                                        } else {
                                            layer.msg(data.msg);
                                        }
                                    }
                                });
                            });
                        }
                    }],
                    // toolbar:'#toolbar',
                    columns: [[
                        { field: 'ck', checkbox: true, align: 'left', width: 50 },
                        { field: 'SupplierName', title: '比价结果', width: 80, align: 'center' },
                        { field: 'FOrderNo', title: '订单编号', width: 120, align: 'center' },
                        { field: 'FShrName', title: '姓名', width: 80, align: 'center' },
                        { field: 'FShrTel', title: '电话', width: 120, align: 'center' },
                        { field: 'FAddress', title: '联系地址', width: 100, align: 'center' },
                        { field: 'FIndex', title: '行号', width: 40, align: 'center' },
                        //--------------------------------------------------------------
                         { field: 'FItemName', title: '产品名称', width: 100, align: 'center' },
                         { field: 'FGgModel', title: '产品型号', width: 100, align: 'center' },
                         { field: 'FQty', title: '数量', width: 50, align: 'center' },
                         { field: 'FWeight', title: '重量', width: 50, align: 'center' },
                         { field: 'FVolume', title: '体积', width: 80, align: 'center' },
                         { field: 'FBjPrice', title: '保价金额', width: 80, align: 'center' },
                        //--------------------------------------------------------------
                        { field: 'FDt', title: '有无电梯', width: 80, align: 'center' },
                        { field: 'TranspPrice1', title: '报价（入户）', width: 100, align: 'center' },
                        { field: 'TranspPrice2', title: '报价（不入户）', width: 100, align: 'center' },
                        {
                            field: 'FOrderId', title: '操作', width: 60, align: 'center', formatter: function (value, row, index) {
                                return '<a href="#" onclick="Grid.ShowDetail(' + value + ')">比价分析</a>';
                            }
                        }
                    ]],
                    onLoadSuccess: onLoadSuccess
                });
            },
            ShowDetail: function (orderid) {
                Grid.layerid = layer.open({
                    type: 2,
                    title: '比价分析',
                    content: '/Order/OrderBjDetail?orderid=' + orderid,
                    area: ['700px', '600px']
                });
                // layer.full(Grid.layerid);
            },
            Refresh: function () {
                Grid.list.datagrid('reload');
            },
            CloseDetail: function () {
                layer.close(Grid.layerid);
            }
        }

        function onLoadSuccess(data) {
            var _orderid;
            var _index = -1;
            var _rowspan = 0;
            for (var i = 0; i < data.rows.length; i++) {
                if (_orderid != data.rows[i].FOrderId) {
                    //合并；
                    if (_rowspan > 1) {
                        mergeCell(_index, _rowspan);
                    }
                    _orderid = data.rows[i].FOrderId;
                    _index = i;
                    _rowspan = 1;
                } else {
                    _rowspan = _rowspan + 1;
                }

            }
            if (_rowspan > 1) {
                mergeCell(_index, _rowspan);
            }
        }
        function mergeCell(_index, _rowspan) {
            $(Grid.list).datagrid('mergeCells', {
                index: _index,
                field: 'ck',
                rowspan: _rowspan
            }).datagrid('mergeCells', {
                index: _index,
                field: 'SupplierName',
                rowspan: _rowspan
            }).datagrid('mergeCells', {
                index: _index,
                field: 'FOrderNo',
                rowspan: _rowspan
            }).datagrid('mergeCells', {
                index: _index,
                field: 'FShrName',
                rowspan: _rowspan
            }).datagrid('mergeCells', {
                index: _index,
                field: 'FShrTel',
                rowspan: _rowspan
            }).datagrid('mergeCells', {
                index: _index,
                field: 'FAddress',
                rowspan: _rowspan
            }).datagrid('mergeCells', {
                index: _index,
                field: 'FCost',
                rowspan: _rowspan
            }).datagrid('mergeCells', {
                index: _index,
                field: 'FOrderId',
                rowspan: _rowspan
            });
        }
    </script>
}